package online.longzipeng.back.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import online.longzipeng.back.common.enums.ResponseEnum;

import java.io.Serializable;

/**
 * @Author: lzp
 * @description:
 * @Date: 2022/5/15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class Result<T> implements Serializable {

    private String message;
    private int code;
    private T data;

    public Result(ResponseEnum responseEnum) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    public Result(String message, int code) {
        this.message = message;
        this.code = code;
    }

    public Result(int code) {
        this.code = code;
    }

    public static Result success() {
        return new Result(ResponseEnum.SUCCESS);
    }

    public static <T> Result success(T data) {
        return new Result(ResponseEnum.SUCCESS.getMessage(), ResponseEnum.SUCCESS.getCode(), data);
    }

    public static Result error(String message) {
        return new Result(message, ResponseEnum.FAILED.getCode());
    }

}
